﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcGambro.Models;

namespace MvcGambro.Controllers
{
    public class Sys_MenuController : Controller
    {
        DBGambroContextDataContext context = new DBGambroContextDataContext();
        public ActionResult Index()
        {
            IList<Sys_Menu> list = context.Sys_Menu.ToList();
            return View(list);
        }
        public ActionResult Create()
        {
            return View();
        }
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                Models.Sys_Menu menu = new Models.Sys_Menu();
                UpdateModel<Models.Sys_Menu>(menu);
                context.Sys_Menu.InsertOnSubmit(menu);
                context.SubmitChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        public ActionResult Edit(int id)
        {
            Models.Sys_Menu menu = context.Sys_Menu.Single(p => p.PKID == id);
            return View(menu);
        }
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                Models.Sys_Menu menu = context.Sys_Menu.Single(p => p.PKID == id);
                UpdateModel<Models.Sys_Menu>(menu);
                menu.PKID = id;
                context.SubmitChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        public ActionResult Delete(int id)
        {
            Models.Sys_Menu menu = context.Sys_Menu.Single(p => p.PKID == id);
            context.Sys_Menu.DeleteOnSubmit(menu);
            context.SubmitChanges();
            return RedirectToAction("Index");
        }
        public ActionResult Details(int id)
        {
            Models.Sys_Menu menu = context.Sys_Menu.Single(p => p.PKID == id);
            return View(menu);
        }
    }
}
